package ml.preprocessing;

import java.io.File;
import java.util.Arrays;
import java.util.List;

import ml.ProcessExecutionUtil;
import ml.UpAndCountDownLatch;

public class FilterRemoveRunnable implements Runnable {
	private final UpAndCountDownLatch latch;
	private final File workingDirectory;
	private final File inputFile;
	private final File outputFile;
	private final String idxList;

	public FilterRemoveRunnable(final UpAndCountDownLatch latch,
			final File workingDirectory, final File inputFile,
			final File outputFile, final String idxList) {
		super();
		this.latch = latch;
		this.workingDirectory = workingDirectory;
		this.inputFile = inputFile;
		this.outputFile = outputFile;
		this.idxList = idxList;
	}

	@Override
	public void run() {
		latch.countUp();
		System.out.println("Execution of filter 'Remove' for file '"
				+ inputFile.getAbsolutePath() + "' started ...");

		final List<String> params = Arrays.asList("java.exe", "-mx4000m",
				"-classpath", "weka.jar",
				"weka.filters.unsupervised.attribute.Remove", "-V", "-R",
				idxList, "-i", inputFile.getAbsolutePath(), "-o",
				outputFile.getAbsolutePath());
		final String output = ProcessExecutionUtil.executeProcess(params,
				workingDirectory.getAbsolutePath());

		System.out.println("Filter 'Remove' for file '"
				+ inputFile.getAbsolutePath() + "' executed.");
		latch.countDown();
	}
}
